package com.right.health.app.ui.main.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.magic.basic.adapter.BaseAbsAdapter;
import com.magic.basic.utils.TimeUtil;
import com.right.health.app.R;
import com.right.health.app.bean.MedicalRecordInfo;
import com.right.health.app.constants.AppConfig;


public class MedicalAdapter extends BaseAbsAdapter<MedicalRecordInfo> {

    private String[] mTypes;

    public MedicalAdapter(Context context) {
        super(context);

        mTypes = getResources().getStringArray(R.array.visit_type_arrays);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(convertView == null) {
            convertView = mInflater.inflate(R.layout.medical_item, null);
            viewHolder = new ViewHolder();

            viewHolder.nameTv = (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.timeTv = (TextView) convertView.findViewById(R.id.tv_time);
            viewHolder.typeTv = (TextView) convertView.findViewById(R.id.tv_type);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        MedicalRecordInfo info = mDataSource.get(position);
        viewHolder.nameTv.setText(info.syscommunityname);
        try {

            viewHolder.timeTv.setText(TimeUtil.convertTime(AppConfig.FORMAT_TIME, info.casehistorytime));
            viewHolder.typeTv.setText(mTypes[Integer.valueOf(info.visittype)]);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return convertView;
    }

    private class ViewHolder {
        private TextView nameTv, timeTv, typeTv;
    }
}
